package com.qx.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.qx.po.Employees;
import com.qx.po.Vip;
import com.qx.service.IVipService;

@Controller
public class VipController {
	 @Autowired
	 public IVipService ivipservice;
	 
	 @RequestMapping("tovip")
	 public String tosupplier(Model model, HttpSession session) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 List<Vip> viplist = ivipservice.selectVipAll();
		 model.addAttribute("viplist", viplist);
		 model.addAttribute("employees", employee);
		 return "/vipinformation1";
		    }
	 @RequestMapping("deletevip/{vno}")
	 public String deletevip(Model model, HttpSession session, @PathVariable("vno") String vno) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 ivipservice.deleteVipByvno(vno);
		 List<Vip> viplist = ivipservice.selectVipAll();
		 model.addAttribute("viplist", viplist);
		 model.addAttribute("employees", employee);
		 return "/vipinformation1";
	 		}
	 
	 @RequestMapping("toupdatevip/{vno}")
	 public String toupdatevip(Model model, HttpSession session, @PathVariable("vno") String vno) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 Vip vip = ivipservice.selectVipByvno(vno);
		 model.addAttribute("vip", vip);
		 model.addAttribute("employees", employee);
		 return "/updatevip";
	 		}

	 @RequestMapping("tovipinformation1/{vno}")
	 public String tovipinformation1(Model model, @PathVariable("vno") String vno, @RequestParam("vname") String vname, @RequestParam("vlevel") String vlevel,
			 @RequestParam("vscore") int vscore, @RequestParam("vtel") String vtel, @RequestParam("vtips") String vtips,
			 HttpSession session) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 Vip vip = new Vip();
		 vip.setVno(vno);
		 vip.setVname(vname);
		 vip.setVlevel(vlevel);
		 vip.setVscore(vscore);
		 vip.setVtel(vtel);
		 vip.setVtips(vtips);
		 ivipservice.updateVipByvno(vip);
		 List<Vip> viplist = ivipservice.selectVipAll();
		 model.addAttribute("viplist", viplist);
		 model.addAttribute("employees", employee);
		 return "/vipinformation1";
	 		}
	 @RequestMapping("toaddvip")
	 public String toaddsupplier(Model model, HttpSession session) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 model.addAttribute("employees", employee);
		 return "/addvip";
	 		}

	 @RequestMapping("addvip")
	 public String addsupplier(@RequestParam("vno") String vno, @RequestParam("vname") String vname, @RequestParam("vlevel") String vlevel,
			 @RequestParam("vscore") int vscore, @RequestParam("vtel") String vtel, @RequestParam("vtips") String vtips,
			 Model model, HttpSession session) throws Exception {
		 Employees employee = (Employees)session.getAttribute("employees");
		 Vip vip = new Vip();
		 vip.setVno(vno);
		 vip.setVname(vname);
		 vip.setVlevel(vlevel);
		 vip.setVscore(vscore);
		 vip.setVtel(vtel);
		 vip.setVtips(vtips);
		 ivipservice.insertVip(vip);
		 List<Vip> viplist = ivipservice.selectVipAll();
		 model.addAttribute("viplist", viplist);
		 model.addAttribute("employees", employee);
		 return "/vipinformation1";
	 		}


}
